home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / RevRdist Folder / RevRdist / RevRdist src / message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-05  |  5.7 KB  |  259 lines  |  [TEXT/KAHL]

  1. /*
  2.  * messages.c - help with formatting and display of messages
  3.  */
  4. #include "RevRdist.h"
  5. #include "TransSkelProto.h"
  6. #include "TransDisplayProto.h"
  7. #include <stdarg.h>
  8.  
  9. extern StringPtr    syserrlist (OSErr);
  10.  
  11.  
  12. /*
  13.  *=========================================================================
  14.  * dispIndStr (w, idx, str, p0, p1, p2, p3) - display STR# with params
  15.  * entry:    w = TransDisplay window to display text in
  16.  *            idx = string index in STR# resource
  17.  *            str = STR# resource id
  18.  *            p0, p1, p2, p3 = strings to substitute into text, if fewer
  19.  *                than 4 strings are needed, end list early with nil
  20.  *=========================================================================
  21.  */
  22.  
  23. void
  24. dispIndStr (
  25.     WindowPtr        w,
  26.     Integer            idx,
  27.     Integer            str,
  28.     StringPtr        p0,
  29.     ...)
  30. {
  31.     Handle            h;
  32.     WindowPtr        oldw;
  33.     Longint            offset;
  34.     Size            len;
  35.     va_list            ap;
  36.     StringPtr        p1, p2, p3;
  37.  
  38.     if (w == nil)
  39.         return;
  40.     h = NewHandle ((Size) 256);
  41.     if (h == nil)
  42.         return;
  43.     p1 = nil; p2 = nil;
  44.     va_start(ap, p0);
  45.     if (p0)
  46.         p1 = va_arg(ap, StringPtr);
  47.     if (p1)
  48.         p2 = va_arg(ap, StringPtr);
  49.     if (p2)
  50.         p3 = va_arg(ap, StringPtr);
  51.     va_end(ap);
  52.     GetDWindow (&oldw);                /* remember current window */
  53.     if (w != oldw)
  54.         SetDWindow (w);                /*  and switch to new window */
  55.     HLock (h);
  56.     GetIndString ((StringPtr) (*h), str, idx);
  57.     if (**h == 0)
  58.         goto eexit;
  59.     HUnlock (h);
  60.     SetHandleSize (h, (Size) (**h) + 1);
  61.     /*
  62.      * For each parameter up to a nil ptr, use Munger to insert it in
  63.      * the text.
  64.      */
  65.     offset = 1;
  66.     if (!p0)
  67.         goto done;
  68.     offset = Munger (h, offset, (Ptr) "^0", 2, &p0[1], (long) p0[0]);
  69.     if (offset < 0)
  70.         goto done;
  71.     if (!p1)
  72.         goto done;
  73.     offset = Munger (h, offset, (Ptr) "^1", 2, &p1[1], (long) p1[0]);
  74.     if (offset < 0)
  75.         goto done;
  76.     if (!p2)
  77.         goto done;
  78.     offset = Munger (h, offset, (Ptr) "^2", 2, &p2[1], (long) p2[0]);
  79.     if (offset < 0)
  80.         goto done;
  81.     if (!p3)
  82.         goto done;
  83.     offset = Munger (h, offset, (Ptr) "^3", 2, &p3[1], (long) p3[0]);
  84.  
  85. done:
  86.     HLock (h);
  87.     if (w == ActivityWind && Depth > 0)
  88.         DisplayText("          ", (Longint)(Depth <= 10 ? Depth : 10));
  89.     len = GetHandleSize (h) - 1;
  90.     DisplayText ((*h)+1, len);
  91.     DisplayLn ();
  92.     if (w == ActivityWind)
  93.     {
  94.         if (len > 255)
  95.             len = 255;
  96.         **h = len;
  97.         statMsg (*(StringHandle)h);
  98.     }
  99. eexit:
  100.     HUnlock (h);
  101.     DisposHandle (h);
  102.     if (w != oldw)
  103.         SetDWindow (oldw);
  104. }
  105.  
  106.  
  107. /*
  108.  *=========================================================================
  109.  * notice (idx, p0, p1, p2, p3) - write msg to activity window
  110.  * entry:    idx = index (L_xxx) of message text
  111.  *            p0, ... = strings to substitute in text
  112.  *=========================================================================
  113.  */
  114. void
  115. notice (enum activity_e    idx, StringPtr p0, ...)
  116. {
  117.     int    i;
  118.     StringPtr        ap0, ap1, ap2, ap3;
  119.     unsigned char    cbuf[20];
  120.     va_list            ap;
  121.  
  122.     va_start(ap, p0);
  123.     i = 0;
  124.     if (ap0 = p0) {
  125.         i = 1;
  126.         ap1 = va_arg(ap, StringPtr);
  127.         if (ap1) {
  128.             i = 2;
  129.             ap2 = va_arg(ap, StringPtr);
  130.             if (ap2) {
  131.                 i = 3;
  132.                 ap3 = va_arg(ap, StringPtr);
  133.                 if (ap3)
  134.                     i = 4;
  135.             }
  136.         }
  137.     }
  138.     va_end(ap);
  139.     switch (i)
  140.     {
  141.     case 0:    ap0 = Clue0;
  142.     case 1: ap1 = Clue1;
  143.     case 2: ap2 = (idx == L_SYS || idx == L_FILE) ? syserrlist(ClueID) : Clue2;
  144.     case 3: ap3 = Clue3;
  145.     }
  146.     dispIndStr (ActivityWind, idx, LST_STR, ap0, ap1, ap2, ap3);
  147. }
  148.  
  149.  
  150. /*
  151.  *=========================================================================
  152.  * panic (f, idx, p0, p1, p2) - display panic alert
  153.  * entry:    f = false if user can choose to ignore error
  154.  *            idx = index in ERR_STR of text
  155.  *            p0, p1, p2 = substitutable text
  156.  * exit:    Quit set true if user selects CANCEL
  157.  *=========================================================================
  158.  */
  159.  
  160. void
  161. panic (Boolean f, enum error_e idx, StringPtr p0, ...)
  162. {
  163.     Integer    i;
  164.     Integer oldresfile;
  165.     StringPtr        ap0, ap1, ap2;
  166.     Str255            buf;
  167.     unsigned char    cbuf[20];
  168.     va_list            ap;
  169.  
  170.     va_start(ap, p0);
  171.     i = 0;
  172.     if (ap0 = p0) {
  173.         i = 1;
  174.         ap1 = va_arg(ap, StringPtr);
  175.         if (ap1) {
  176.             i = 2;
  177.             ap2 = va_arg(ap, StringPtr);
  178.             if (ap2)
  179.                 i = 3;
  180.         }
  181.     }
  182.     va_end(ap);
  183.     switch (i)
  184.     {
  185.     case 0:    ap0 = Clue0;
  186.     case 1: ap1 = Clue1;
  187.     case 2: ap2 = (idx == E_SYS || idx == E_FILE) ? syserrlist(ClueID) : Clue2;
  188.     }
  189.     oldresfile = CurResFile ();
  190.     UseResFile (Ap_refNum);
  191.     GetIndString (buf, ERR_STR, idx);
  192.     ParamText (ap0, ap1, ap2, buf);
  193.     if (f)
  194.         i = StopAlert (RSRC_BASE+ALERT_PANIC, nil);
  195.     else
  196.         i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
  197.     if (f || i == ALRT_CANCEL)
  198.         Quit = true;
  199.     UseResFile (oldresfile);
  200. }
  201.  
  202. /*
  203.  *=========================================================================
  204.  * warning (idx, p0, p1, p2, p3) - display warning message
  205.  *        in the error and activity windows
  206.  *        and produce an alert unless we are the startup application
  207.  * entry:    idx = index in ERR_STR STR# of text
  208.  *            p0, p1, p2 = substitutable text
  209.  *=========================================================================
  210.  */
  211.  
  212. void
  213. warning (enum error_e idx, StringPtr p0, ...)
  214. {
  215.     Integer    i;
  216.     static    oldidx    = -1;
  217.     Integer oldresfile;
  218.     StringPtr        ap0, ap1, ap2, ap3;
  219.     Str255            buf;
  220.     unsigned char    cbuf[20];
  221.     va_list            ap;
  222.  
  223.     va_start(ap, p0);
  224.     i = 0;
  225.     if (ap0 = p0) {
  226.         i = 1;
  227.         ap1 = va_arg(ap, StringPtr);
  228.         if (ap1) {
  229.             i = 2;
  230.             ap2 = va_arg(ap, StringPtr);
  231.             if (ap2)
  232.                 i = 3;
  233.         }
  234.     }
  235.     va_end(ap);
  236.     switch (i)
  237.     {
  238.     case 0:    ap0 = Clue0;
  239.     case 1: ap1 = Clue1;
  240.     case 2: ap2 = (idx == E_SYS || idx == E_FILE) ? syserrlist(ClueID) : Clue2;
  241.     }
  242.     oldresfile = CurResFile ();
  243.     UseResFile (Ap_refNum);
  244.     dispIndStr (ActivityWind, idx, ERR_STR, ap0, ap1, ap2, nil);
  245.     dispIndStr (ErrorWind, idx, ERR_STR, ap0, ap1, ap2, nil);
  246.     ErrorMsgs++;
  247.     if (idx == E_DOQUIT || (!(Flags & PF_STARTUP) && idx != oldidx) )
  248.     {
  249.         GetIndString (buf, ERR_STR, idx);
  250.         ParamText (ap0, ap1, ap2, buf);
  251.         i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
  252.         if (i == ALRT_CANCEL)
  253.             Quit = true;
  254.     }
  255.     if (Flags & PF_STARTUP)
  256.         Quit = true;
  257.     oldidx = idx;
  258.     UseResFile (oldresfile);
  259. }